package mysqlinit

import "gorm.io/gorm"

type House struct {
	gorm.Model
	UserId      int     `gorm:"type:int(11);not null commit:用户ID"`
	City        string  `gorm:"type:varchar(40);not null commit:城市"`
	Address     string  `gorm:"type:varchar(45);not null commit:小区地址"`
	HouseCode   string  `gorm:"type:varchar(15);not null commit:楼栋号"`
	HouseFloor  string  `gorm:"type:varchar(15);not null commit:楼层"`
	HouseAcre   string  `gorm:"type:varchar(20);not null commit:房屋面积"`
	HousePrice  float64 `gorm:"type:decimal(10,2);not null commit:月租金"`
	Describe    string  `gorm:"type:varchar(100);not null commit:房源描述"`
	HouseStatus int     `gorm:"type:tinyint(1);default:1;not null commit:1 未上架 2 已上架 3已下架"`
}

func (h *House) CreateHouse() error {
	return DB.Debug().Create(&h).Error
}
func (h *House) FindHouse(houseId int64) error {
	return DB.Debug().Where("id = ?", houseId).Find(&h).Error
}
func (h *House) UpdateHouseStatus(houseId int64, houseStatus int64) error {
	return DB.Debug().Model(&h).Where("id = ?", houseId).Update("house_status", houseStatus).Error
}

type HouseCover struct {
	gorm.Model
	HouseId int    `gorm:"type:int(11);not null commit:房屋Id"`
	Living  string `gorm:"type:varchar(200);not null commit:客厅"`
	Sleep   string `gorm:"type:varchar(200);not null commit:卧室"`
	Kitchen string `gorm:"type:varchar(200);not null commit:厨房"`
	Toilet  string `gorm:"type:varchar(200);not null commit:卫生间"`
}

func (hc *HouseCover) CreateHouseCover() error {
	return DB.Debug().Create(&hc).Error
}
func (hc *HouseCover) FindHouseCover(houseCoverId int64) error {
	return DB.Debug().Where("id = ?", houseCoverId).Find(&hc).Error
}
